package greedyAlgorithm;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @program: data_structures_algorithms
 * @description:
 * @author: lld
 * @create: 2020-11-19 17:29
 **/
public class Demo1 {
    public static void main(String[] args) {
        int[] n={8,3,4};
        List<Integer> list = minSubsequence(n);
        System.out.println(list);
    }
    public static List<Integer> minSubsequence(int[] nums) {
        List<Integer> list=new ArrayList<>();
        if(nums==null){
            return null;
        }
//        if(nums.length==1){
//            list.add(nums[0]);
//            return list;
//        }
        Arrays.sort(nums);
        int leftSum=0,sum=0;
        for(int i:nums){
            leftSum+=i;
        }
        for (int i = nums.length-1;i>=0 ; i--) {
            sum+=nums[i];
            leftSum-=nums[i];
                list.add(nums[i]);
            if(leftSum<sum){
                break;
            }
        }
        return list;
    }
}
